package com.huitone.smspfm.oldclient.asserver.report;

import java.io.IOException;

import org.dom4j.DocumentException;

import com.bin.common.utils.StringUtils;
import com.huitone.smspfm.context.utils.ContextPropertiesUtils;
import com.huitone.smspfm.oldclient.core.TestFileWriter;
import com.huitone.smspfm.oldclient.model.ReportSms;

/**   
* @Title: ReportFileWriter.java 
* @Package com.unicom.gddw.module.report 
* @Description: TODO(用一句话描述该文件做什么) 
* @author ybliang   
* @date 2017年3月17日 上午11:02:12 
* @version V1.0   
*/
public class ReportFileWriter extends TestFileWriter {
	
	
	private String rptFileDir = null;
	
	public ReportFileWriter() {
		
		this.setLineToCut(StringUtils.toLongP(ContextPropertiesUtils.getProperty("report.file.maxsplit.rowcount"), 1000));
		this.setTimeToCut(StringUtils.toLongP(ContextPropertiesUtils.getProperty("report.file.maxsplit.interal"), 60 * 1000));
		this.setWrapLeft("<data>");
		this.setWrapRight("</data>");
		
		rptFileDir = ContextPropertiesUtils.getProperty("smspfm.client.file.dir.report");
		
		this.setFilePath(rptFileDir);
		this.setFileName("report.tmp");
		this.setCutFileName(this.new CutFileNameCofig("report_", ".xml"));
		this.init();
		this.enableWatchDog();
		
	}

	/**
	 * 将上行短信写入到文件
	 * @param report
	 * @throws IOException
	 * @throws DocumentException
	 */
	@Override
	public synchronized void write(Object obj) throws IOException {
		
		if (obj == null) {
			return;
		}
		
		if (obj instanceof ReportSms) {
			
			ReportSms reportSms = (ReportSms) obj;
			
			writeLine(reportSms.toString());
		}
	}

	public String getRptFileDir() {
		return rptFileDir;
	}

	public void setRptFileDir(String rptFileDir) {
		this.rptFileDir = rptFileDir;
	}
}
